import java.util.Stack;

/**
 * @Description: 用栈实现队列
 * https://leetcode.cn/problems/implement-queue-using-stacks/
 * @Date:Create in 21:37  2022/7/11
 */

public class MyQueue0232 {

    Stack<Integer> stackIn;
    Stack<Integer> stackOut;

    public MyQueue0232() {
        stackIn = new Stack<>();//负责进栈
        stackOut = new Stack<>();//负责出栈

    }

    public void push(int x) {
        stackIn.push(x);
    }

    public int pop() {
        dumpstackIn();
        return stackOut.pop();
    }

    public int peek() {
        dumpstackIn();
        return stackOut.peek();
    }

    public boolean empty() {
        return stackIn.isEmpty() && stackOut.isEmpty();
    }

    private void dumpstackIn(){
        if(!stackOut.isEmpty()) return;
        while(!stackIn.isEmpty()){
            stackOut.push(stackIn.pop());
        }
    }

}
